package top.minuy.test;

import java.util.Objects;

/**
 * @author Minuy
 * @time 21:45
 * @date 2021/11/8
 */
public class Cat<K extends Comparable<K>, V>{
    private class Node implements Comparable<Node>{
        public K key;
        public V val;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Node node = (Node) o;
            return Objects.equals(key, node.key);
        }

        @Override
        public int hashCode() {
            return Objects.hash(key);
        }

        @Override
        public int compareTo(Node e) {
            return key.compareTo(e.key);
        }
    }
    private static class Dog<E extends Comparable<E>> extends Animal<E>{
        public Dog(int capacity) {
            super(capacity);
        }
    }

    Dog<Node> data;

    public Cat(int capacity) {
        data = new Dog<>(capacity);
    }

    public boolean add(K key,V val){
        Node e = new Node();
        e.key = key;
        e.val = val;
        return data.add(e);
    }

    public V get(K key){
        Node k = new Node();
        k.key = key;
        k = data.get(k);
        return k==null?null:k.val;
    }
}
